package com.notify;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.Button;

public class NotificationsActivity extends Activity {
    /** Called when the activity is first created. */
	
	
	
	
	private final static int NOTIFY_ME_ID = 1137;
	private Timer timer = new Timer();
	private int count = 0;
	private Button btn1,btn2;
	
	
	private void notifyMe() {
		
		
		final NotificationManager manger = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		Notification note = new Notification(R.drawable.hello,"status message",System.currentTimeMillis());
		PendingIntent i = PendingIntent.getActivity(this, 0,new Intent(this,Message.class), 0);
		note.setLatestEventInfo(this, "NotificationTitle", "this is a notification", i);
		note.number = ++count;
		note.defaults |= Notification.DEFAULT_SOUND;
		/*note.defaults |= Notification.DEFAULT_VIBRATE;*/
		manger.notify(NOTIFY_ME_ID,note);
		
		
	}
	
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        
        btn1 = (Button) findViewById(R.id.button1);
        btn2 = (Button) findViewById(R.id.button2);
        
        
        
        btn1.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				TimerTask task = new TimerTask(){
					public void run(){
						notifyMe();
					}

					
				};
				
			timer.schedule(task,5000);
			
			}
		});
        
        
       
        btn2.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				
				
				NotificationManager manger = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
				manger.cancel(NOTIFY_ME_ID);
				
				
			}
		});
        
        
    }
}